package com.back.end.Service.impl;

import com.back.end.Dao.AdminDao;
import com.back.end.Modal.Admin;
import com.back.end.Service.AdminService;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import javax.annotation.Resource;

@Service
public class AdminServiceImpl implements AdminService {
    @Resource
    AdminDao adminDao;

    @Override
    public boolean find_admin(Admin admin) {
        Admin ad = adminDao.findPasswordByUsername(admin.getUsername());
        if (ad == null) {
            return false;
        }
        return ad.getPassword().equals(DigestUtils.md5DigestAsHex(admin.getPassword().getBytes()));
    }

    @Override
    public void rest_password(Admin admin) {

        Admin ad = adminDao.findPasswordByUsername(admin.getUsername());
        if (ad == null) {
            return;
        }
        String MD5Password = DigestUtils.md5DigestAsHex(admin.getPassword().getBytes());
        Integer rows = adminDao.restAdminPassword(admin.getUsername(), MD5Password);
        if (rows == -1) {
            throw new RuntimeException("更新失败");
        }
    }
}
